<?php

class Edm_Controller_Plugin_Common extends Zend_Controller_Plugin_Abstract {

    // route 结束时
    public function routeShutdown(Zend_Controller_Request_Abstract $request) {
        // 获取模块名，如 admin，front 等
        $module = $request->getModuleName();

        // bootstrap 类
        $this->_bootstrap = Zend_Controller_Front::getInstance()->getParam('bootstrap');

        // 加载 view
        $this->_bootstrap->bootstrap('View');
        $view = $this->_bootstrap->getResource('View');
        $moduleParams = $view->$module;

        // 配置 view
        $view->addBasePath($moduleParams['basePath'])
                ->addHelperPath($moduleParams['helperPath'],
                        $moduleParams['helperPathPrefix']);

        // 加载 layout 并配置
        $this->_bootstrap->bootstrap('Layout');
        $layout = $this->_bootstrap->getResource('Layout');
        $layout->setLayoutPath($moduleParams['layoutPath'])
                ->setLayout($moduleParams['layout']);

        //初始化，配置数据库
        $resource = $this->_bootstrap->getPluginResource('db');
        $db = $resource->getDbAdapter();
        Zend_Db_Table::setDefaultAdapter($db);
        Zend_Registry::set('db', $db);
    }

}